<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>购物车实现 | 美多商城</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../C04-Cart/MergeCart.html" />
    
    
    <link rel="prev" href="../C04-Cart/DataStructureDesign.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="4.2"
        data-chapter-title="购物车实现"
        data-filepath="C04-Cart/Implement.md"
        data-basepath=".."
        data-revision="Thu May 24 2018 15:58:46 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        美多商城
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-Prepare/index.html">
            
                
                    <a href="../C01-Prepare/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        项目准备
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-Prepare/BusinessModel.html">
            
                
                    <a href="../C01-Prepare/BusinessModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        商业模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-Prepare/DevelopmentProcess.html">
            
                
                    <a href="../C01-Prepare/DevelopmentProcess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        开发流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-Prepare/ProductAnalysis.html">
            
                
                    <a href="../C01-Prepare/ProductAnalysis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        需求分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="C01-Prepare/ProjectStructure.html">
            
                
                    <a href="../C01-Prepare/ProjectStructure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        项目架构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="C01-Prepare/StartProject.html">
            
                
                    <a href="../C01-Prepare/StartProject.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        创建工程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="C01-Prepare/Config.html">
            
                
                    <a href="../C01-Prepare/Config.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-Users/index.html">
            
                
                    <a href="../C02-Users/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        用户部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-Users/UserModel.html">
            
                
                    <a href="../C02-Users/UserModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        用户模型类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C02-Users/Register.html">
            
                
                    <a href="../C02-Users/Register.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="C02-Users/CORS.html">
            
                
                    <a href="../C02-Users/CORS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        跨域CORS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="C02-Users/JWT.html">
            
                
                    <a href="../C02-Users/JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="C02-Users/DRF-JWT.html">
            
                
                    <a href="../C02-Users/DRF-JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        Django REST framework JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="C02-Users/Login.html">
            
                
                    <a href="../C02-Users/Login.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        登录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="C02-Users/FindPassword/index.html">
            
                
                    <a href="../C02-Users/FindPassword/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        找回密码
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="C02-Users/FindPassword/Step1.html">
            
                
                    <a href="../C02-Users/FindPassword/Step1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.1.</b>
                        
                        第一步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="C02-Users/FindPassword/Step2.html">
            
                
                    <a href="../C02-Users/FindPassword/Step2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.2.</b>
                        
                        第二步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.3" data-path="C02-Users/FindPassword/Step3.html">
            
                
                    <a href="../C02-Users/FindPassword/Step3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.3.</b>
                        
                        第三步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.4" data-path="C02-Users/FindPassword/Step4.html">
            
                
                    <a href="../C02-Users/FindPassword/Step4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.4.</b>
                        
                        第四步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="C02-Users/QQLogin/index.html">
            
                
                    <a href="../C02-Users/QQLogin/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        QQ登录
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.8.1" data-path="C02-Users/QQLogin/Step1.html">
            
                
                    <a href="../C02-Users/QQLogin/Step1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.1.</b>
                        
                        第一步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8.2" data-path="C02-Users/QQLogin/Step2.html">
            
                
                    <a href="../C02-Users/QQLogin/Step2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.2.</b>
                        
                        第二步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8.3" data-path="C02-Users/QQLogin/Step3.html">
            
                
                    <a href="../C02-Users/QQLogin/Step3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.3.</b>
                        
                        第三步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="C02-Users/UserInfo.html">
            
                
                    <a href="../C02-Users/UserInfo.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        用户中心个人信息
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="C02-Users/Email/index.html">
            
                
                    <a href="../C02-Users/Email/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        邮件与验证
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.10.1" data-path="C02-Users/Email/DjangoEmail.html">
            
                
                    <a href="../C02-Users/Email/DjangoEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.1.</b>
                        
                        Django发送邮件的方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10.2" data-path="C02-Users/Email/SendEmail.html">
            
                
                    <a href="../C02-Users/Email/SendEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.2.</b>
                        
                        保存邮箱并发送验证邮件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10.3" data-path="C02-Users/Email/VerifyEmail.html">
            
                
                    <a href="../C02-Users/Email/VerifyEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.3.</b>
                        
                        验证邮箱链接
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="C02-Users/Address/index.html">
            
                
                    <a href="../C02-Users/Address/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        收货地址
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.11.1" data-path="C02-Users/Address/AreaSelect.html">
            
                
                    <a href="../C02-Users/Address/AreaSelect.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.1.</b>
                        
                        省市区地址查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11.2" data-path="C02-Users/Address/Cache.html">
            
                
                    <a href="../C02-Users/Address/Cache.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.2.</b>
                        
                        使用缓存
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11.3" data-path="C02-Users/Address/UserAddressManagement.html">
            
                
                    <a href="../C02-Users/Address/UserAddressManagement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.3.</b>
                        
                        用户地址管理
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Goods/index.html">
            
                
                    <a href="../C03-Goods/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        商品部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Goods/DatabaseDesign.html">
            
                
                    <a href="../C03-Goods/DatabaseDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        数据表设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Goods/FastDFS.html">
            
                
                    <a href="../C03-Goods/FastDFS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        FastDFS分布式文件系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Goods/Docker/index.html">
            
                
                    <a href="../C03-Goods/Docker/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Docker使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="C03-Goods/Docker/Introduce.html">
            
                
                    <a href="../C03-Goods/Docker/Introduce.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        Docker简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="C03-Goods/Docker/InstallAndOperations.html">
            
                
                    <a href="../C03-Goods/Docker/InstallAndOperations.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        安装与操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Goods/FastDFSDocker.html">
            
                
                    <a href="../C03-Goods/FastDFSDocker.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        使用Docker安装FastDFS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="C03-Goods/FastDFSClientAndDjangoFileSystem.html">
            
                
                    <a href="../C03-Goods/FastDFSClientAndDjangoFileSystem.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        FastDFS客户端与自定义文件存储系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="C03-Goods/CKEditor.html">
            
                
                    <a href="../C03-Goods/CKEditor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        CKEditor富文本编辑器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="C03-Goods/ImportGoodsData.html">
            
                
                    <a href="../C03-Goods/ImportGoodsData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        添加测试数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="C03-Goods/FreezeHTML.html">
            
                
                    <a href="../C03-Goods/FreezeHTML.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        页面静态化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="C03-Goods/DjangoCrontab.html">
            
                
                    <a href="../C03-Goods/DjangoCrontab.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        定时任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="C03-Goods/GenerateIndexHTMLScript.html">
            
                
                    <a href="../C03-Goods/GenerateIndexHTMLScript.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        静态化首页的手动脚本
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="C03-Goods/GoodsDetail.html">
            
                
                    <a href="../C03-Goods/GoodsDetail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.11.</b>
                        
                        商品详情页面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="C03-Goods/HotSaleGoods.html">
            
                
                    <a href="../C03-Goods/HotSaleGoods.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.12.</b>
                        
                        热销商品
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="C03-Goods/UserBrowseHistory.html">
            
                
                    <a href="../C03-Goods/UserBrowseHistory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.13.</b>
                        
                        用户浏览历史记录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.14" data-path="C03-Goods/GoodsList.html">
            
                
                    <a href="../C03-Goods/GoodsList.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.14.</b>
                        
                        商品列表页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.15" data-path="C03-Goods/GoodsSearch.html">
            
                
                    <a href="../C03-Goods/GoodsSearch.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.15.</b>
                        
                        商品搜索
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-Cart/index.html">
            
                
                    <a href="../C04-Cart/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        购物车部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C04-Cart/DataStructureDesign.html">
            
                
                    <a href="../C04-Cart/DataStructureDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        购物车数据存储设计
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="4.2" data-path="C04-Cart/Implement.html">
            
                
                    <a href="../C04-Cart/Implement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        购物车实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-Cart/MergeCart.html">
            
                
                    <a href="../C04-Cart/MergeCart.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        登录合并购物车
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-Order/index.html">
            
                
                    <a href="../C05-Order/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        订单部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-Order/OrderDBModel.html">
            
                
                    <a href="../C05-Order/OrderDBModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        订单数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-Order/PlaceOrder.html">
            
                
                    <a href="../C05-Order/PlaceOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        订单结算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="C05-Order/SaveOrder.html">
            
                
                    <a href="../C05-Order/SaveOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        保存订单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="C05-Order/OrderSuccess.html">
            
                
                    <a href="../C05-Order/OrderSuccess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        下单成功
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="C06-Pay/index.html">
            
                
                    <a href="../C06-Pay/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        支付宝支付
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="C06-Pay/Alipay.html">
            
                
                    <a href="../C06-Pay/Alipay.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        接入支付宝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="C06-Pay/Paying.html">
            
                
                    <a href="../C06-Pay/Paying.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        发起支付
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="C06-Pay/PaymentResult.html">
            
                
                    <a href="../C06-Pay/PaymentResult.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        保存支付结果
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="C07-Xadmin.html">
            
                
                    <a href="../C07-Xadmin.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        Xadmin
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="C08-Permission.html">
            
                
                    <a href="../C08-Permission.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        用户权限控制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="C09-Database/index.html">
            
                
                    <a href="../C09-Database/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        数据库读写分离
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="C09-Database/MasterSlave.html">
            
                
                    <a href="../C09-Database/MasterSlave.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        主从同步配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="C09-Database/ReadWriteSeparate.html">
            
                
                    <a href="../C09-Database/ReadWriteSeparate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        Django数据库读写分离
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="C10-Deploy.html">
            
                
                    <a href="../C10-Deploy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        Django部署
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >美多商城</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x8D2D;&#x7269;&#x8F66;&#x5B9E;&#x73B0;">&#x8D2D;&#x7269;&#x8F66;&#x5B9E;&#x73B0;</h1>
<h2 id="1---&#x6DFB;&#x52A0;&#x5230;&#x8D2D;&#x7269;&#x8F66;">1.   &#x6DFB;&#x52A0;&#x5230;&#x8D2D;&#x7269;&#x8F66;</h2>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;</h4>
<p>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F; &#xFF1A; POST  /cart/</p>
<p>&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x662F;&#x5426;&#x5FC5;&#x987B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>sku_id</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x5546;&#x54C1;sku id</td>
</tr>
<tr>
<td>count</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x6570;&#x91CF;</td>
</tr>
<tr>
<td>selected</td>
<td>bool</td>
<td>&#x5426;</td>
<td>&#x662F;&#x5426;&#x52FE;&#x9009;&#xFF0C;&#x9ED8;&#x8BA4;&#x52FE;&#x9009;</td>
</tr>
</tbody>
</table>
<p>&#x8FD4;&#x56DE;&#x6570;&#x636E;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x662F;&#x5426;&#x5FC5;&#x987B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>sku_id</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x5546;&#x54C1;sku id</td>
</tr>
<tr>
<td>count</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x6570;&#x91CF;</td>
</tr>
<tr>
<td>selected</td>
<td>bool</td>
<td>&#x662F;</td>
<td>&#x662F;&#x5426;&#x52FE;&#x9009;&#xFF0C;&#x9ED8;&#x8BA4;&#x52FE;&#x9009;</td>
</tr>
</tbody>
</table>
<p><strong>&#x8BBF;&#x95EE;&#x6B64;&#x63A5;&#x53E3;&#xFF0C;&#x65E0;&#x8BBA;&#x7528;&#x6237;&#x662F;&#x5426;&#x767B;&#x5F55;&#xFF0C;&#x524D;&#x7AEF;&#x8BF7;&#x6C42;&#x90FD;&#x9700;&#x643A;&#x5E26;&#x8BF7;&#x6C42;&#x5934;Authorization&#xFF0C;&#x7531;&#x540E;&#x7AEF;&#x5224;&#x65AD;&#x662F;&#x5426;&#x767B;&#x5F55;</strong></p>
<h4 id="&#x540E;&#x7AEF;&#x7F16;&#x5199;">&#x540E;&#x7AEF;&#x7F16;&#x5199;</h4>
<p><strong>&#x56E0;&#x4E3A;&#x524D;&#x7AEF;&#x53EF;&#x80FD;&#x643A;&#x5E26;cookie&#xFF0C;&#x4E3A;&#x4E86;&#x4FDD;&#x8BC1;&#x8DE8;&#x57DF;&#x8BF7;&#x6C42;&#x4E2D;&#xFF0C;&#x5141;&#x8BB8;&#x540E;&#x7AEF;&#x4F7F;&#x7528;cookie&#xFF0C;&#x786E;&#x4FDD;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x6709;&#x5982;&#x4E0B;&#x8BBE;&#x7F6E;</strong></p>
<pre><code class="lang-python">CORS_ALLOW_CREDENTIALS = <span class="hljs-keyword">True</span>
</code></pre>
<p>&#x521B;&#x5EFA;&#x5E94;&#x7528;carts&#x3002;</p>
<p>&#x5728;carts/serialziers.py&#x4E2D;&#x521B;&#x5EFA;&#x5E8F;&#x5217;&#x5316;&#x5668;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CartSerializer</span><span class="hljs-params">(serializers.Serializer)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;&#x5E8F;&#x5217;&#x5316;&#x5668;
    &quot;&quot;&quot;</span>
    sku_id = serializers.IntegerField(label=<span class="hljs-string">&apos;sku id &apos;</span>, required=<span class="hljs-keyword">True</span>, min_value=<span class="hljs-number">1</span>)
    count = serializers.IntegerField(label=<span class="hljs-string">&apos;&#x6570;&#x91CF;&apos;</span>, required=<span class="hljs-keyword">True</span>, min_value=<span class="hljs-number">1</span>)
    selected = serializers.BooleanField(label=<span class="hljs-string">&apos;&#x662F;&#x5426;&#x52FE;&#x9009;&apos;</span>, default=<span class="hljs-keyword">True</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">validate</span><span class="hljs-params">(self, data)</span>:</span>
        <span class="hljs-keyword">try</span>:
            sku = SKU.objects.get(id=data[<span class="hljs-string">&apos;sku_id&apos;</span>])
        <span class="hljs-keyword">except</span> SKU.DoesNotExist:
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x5546;&#x54C1;&#x4E0D;&#x5B58;&#x5728;&apos;</span>)

        <span class="hljs-keyword">if</span> data[<span class="hljs-string">&apos;count&apos;</span>] &gt; sku.stock:
            <span class="hljs-keyword">raise</span> serializers.ValidationError(<span class="hljs-string">&apos;&#x5546;&#x54C1;&#x5E93;&#x5B58;&#x4E0D;&#x8DB3;&apos;</span>)

        <span class="hljs-keyword">return</span> data
</code></pre>
<p>&#x7F16;&#x5199;&#x89C6;&#x56FE;&#xFF1A;</p>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x56E0;&#x4E3A;&#x524D;&#x7AEF;&#x8BF7;&#x6C42;&#x65F6;&#x643A;&#x5E26;&#x4E86;Authorization&#x8BF7;&#x6C42;&#x5934;&#xFF0C;&#x800C;&#x5982;&#x679C;&#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;&#xFF0C;&#x6B64;&#x8BF7;&#x6C42;&#x5934;&#x65E0;&#x610F;&#x4E49;&#xFF0C;&#x4E3A;&#x4E86;&#x9632;&#x6B62;REST framework&#x6846;&#x67B6;&#x5728;&#x9A8C;&#x8BC1;&#x6B64;&#x65E0;&#x610F;&#x4E49;&#x7684;&#x8BF7;&#x6C42;&#x5934;&#x65F6;&#x629B;&#x51FA;401&#x5F02;&#x5E38;&#xFF0C;&#x5728;&#x89C6;&#x56FE;&#x4E2D;&#x9700;&#x8981;&#x505A;&#x4E24;&#x4E2A;&#x5904;&#x7406;</p>
<ul>
<li>&#x91CD;&#x5199;perform_authentication()&#x65B9;&#x6CD5;&#xFF0C;&#x6B64;&#x65B9;&#x6CD5;&#x662F;REST framework&#x68C0;&#x67E5;&#x7528;&#x6237;&#x8EAB;&#x4EFD;&#x7684;&#x65B9;&#x6CD5;</li>
<li>&#x5728;&#x83B7;&#x53D6;request.user&#x5C5E;&#x6027;&#x65F6;&#x6355;&#x83B7;&#x5F02;&#x5E38;&#xFF0C;REST framework&#x5728;&#x8FD4;&#x56DE;user&#x65F6;&#xFF0C;&#x4F1A;&#x68C0;&#x67E5;Authorization&#x8BF7;&#x6C42;&#x5934;&#xFF0C;&#x65E0;&#x6548;&#x7684;Authorization&#x8BF7;&#x6C42;&#x5934;&#x4F1A;&#x5BFC;&#x81F4;&#x629B;&#x51FA;&#x5F02;&#x5E38;</li>
</ul>
<p>&#x5728;carts/views.py&#x4E2D;&#x521B;&#x5EFA;&#x89C6;&#x56FE;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CartView</span><span class="hljs-params">(APIView)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x8D2D;&#x7269;&#x8F66;
    &quot;&quot;&quot;</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">perform_authentication</span><span class="hljs-params">(self, request)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x91CD;&#x5199;&#x7236;&#x7C7B;&#x7684;&#x7528;&#x6237;&#x9A8C;&#x8BC1;&#x65B9;&#x6CD5;&#xFF0C;&#x4E0D;&#x5728;&#x8FDB;&#x5165;&#x89C6;&#x56FE;&#x524D;&#x5C31;&#x68C0;&#x67E5;JWT
        &quot;&quot;&quot;</span>
        <span class="hljs-keyword">pass</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">post</span><span class="hljs-params">(self, request)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x6DFB;&#x52A0;&#x8D2D;&#x7269;&#x8F66;
        &quot;&quot;&quot;</span>
        serializer = CartSerializer(data=request.data)
        serializer.is_valid(raise_exception=<span class="hljs-keyword">True</span>)
        sku_id = serializer.data.get(<span class="hljs-string">&apos;sku_id&apos;</span>)
        count = serializer.data.get(<span class="hljs-string">&apos;count&apos;</span>)
        selected = serializer.data.get(<span class="hljs-string">&apos;selected&apos;</span>)

        <span class="hljs-comment"># &#x5C1D;&#x8BD5;&#x5BF9;&#x8BF7;&#x6C42;&#x7684;&#x7528;&#x6237;&#x8FDB;&#x884C;&#x9A8C;&#x8BC1;</span>
        <span class="hljs-keyword">try</span>:
            user = request.user
        <span class="hljs-keyword">except</span> Exception:
            <span class="hljs-comment"># &#x9A8C;&#x8BC1;&#x5931;&#x8D25;&#xFF0C;&#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;</span>
            user = <span class="hljs-keyword">None</span>

        <span class="hljs-keyword">if</span> user <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">None</span> <span class="hljs-keyword">and</span> user.is_authenticated:
            <span class="hljs-comment"># &#x7528;&#x6237;&#x5DF2;&#x767B;&#x5F55;&#xFF0C;&#x5728;redis&#x4E2D;&#x4FDD;&#x5B58;</span>
            redis_conn = get_redis_connection(<span class="hljs-string">&apos;cart&apos;</span>)
            pl = redis_conn.pipeline()
            <span class="hljs-comment"># &#x8BB0;&#x5F55;&#x8D2D;&#x7269;&#x8F66;&#x5546;&#x54C1;&#x6570;&#x91CF;</span>
            pl.hincrby(<span class="hljs-string">&apos;cart_%s&apos;</span> % user.id, sku_id, count)
            <span class="hljs-comment"># &#x8BB0;&#x5F55;&#x8D2D;&#x7269;&#x8F66;&#x7684;&#x52FE;&#x9009;&#x9879;</span>
            pl.sadd(<span class="hljs-string">&apos;cart_selected_%s&apos;</span> % user.id, sku_id)
            pl.execute()
            <span class="hljs-keyword">return</span> Response(serializer.data)
        <span class="hljs-keyword">else</span>:
            <span class="hljs-comment"># &#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;&#xFF0C;&#x5728;cookie&#x4E2D;&#x4FDD;&#x5B58;</span>
            <span class="hljs-comment"># {</span>
            <span class="hljs-comment">#     1001: { &quot;count&quot;: 10, &quot;selected&quot;: true},</span>
            <span class="hljs-comment">#     ...</span>
            <span class="hljs-comment"># }</span>
            <span class="hljs-comment"># &#x4F7F;&#x7528;pickle&#x5E8F;&#x5217;&#x5316;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;&#xFF0C;pickle&#x64CD;&#x4F5C;&#x7684;&#x662F;bytes&#x7C7B;&#x578B;</span>
            cart = request.COOKIES.get(<span class="hljs-string">&apos;cart&apos;</span>)
            <span class="hljs-keyword">if</span> cart <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">None</span>:
                cart = pickle.loads(base64.b64decode(cart.encode()))
            <span class="hljs-keyword">else</span>:
                cart = {}

            sku = cart.get(sku_id)
            <span class="hljs-keyword">if</span> sku:
                count += int(sku.get(<span class="hljs-string">&apos;count&apos;</span>))

            cart[sku_id] = {
                <span class="hljs-string">&apos;count&apos;</span>: count,
                <span class="hljs-string">&apos;selected&apos;</span>: <span class="hljs-keyword">True</span>
            }
            response = Response(serializer.data)
            response.set_cookie(<span class="hljs-string">&apos;cart&apos;</span>, base64.b64encode(pickle.dumps(cart)).decode())
            <span class="hljs-keyword">return</span> response
</code></pre>
<h4 id="&#x524D;&#x7AEF;&#x7F16;&#x5199;">&#x524D;&#x7AEF;&#x7F16;&#x5199;</h4>
<p>&#x5728;detail.js&#x4E2D;&#x7F16;&#x5199;&#x6DFB;&#x52A0;&#x8D2D;&#x7269;&#x8F66;&#x7684;&#x8C03;&#x7528;</p>
<p><strong>&#x6CE8;&#x610F;&#xFF1A;&#x524D;&#x7AEF;&#x5728;&#x6B64;&#x8DE8;&#x57DF;&#x8BF7;&#x6C42;&#x4E2D;&#x8981;&#x643A;&#x5E26;cookie&#xFF0C;&#x9700;&#x8981;&#x5728;axios&#x4E2D;&#x6DFB;&#x52A0;&#x914D;&#x7F6E;withCredentials: true</strong></p>
<pre><code class="lang-js">         <span class="hljs-comment">// &#x6DFB;&#x52A0;&#x8D2D;&#x7269;&#x8F66;</span>
        add_cart: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            axios.post(<span class="hljs-keyword">this</span>.host+<span class="hljs-string">&apos;/cart/&apos;</span>, {
                    sku_id: <span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.sku_id),
                    count: <span class="hljs-keyword">this</span>.sku_count
                }, {
                    headers: {
                        <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                    },
                    responseType: <span class="hljs-string">&apos;json&apos;</span>,
                    withCredentials: <span class="hljs-literal">true</span>
                })
                .then(response =&gt; {
                    <span class="hljs-keyword">this</span>.cart_total_count += response.data.count;
                })
                .catch(error =&gt; {
                    alert(error.response.message[<span class="hljs-number">0</span>]);
                    <span class="hljs-built_in">console</span>.log(error.response.data);
                })
</code></pre>
<h2 id="2--&#x67E5;&#x8BE2;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;">2.  &#x67E5;&#x8BE2;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</h2>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;</h4>
<p>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F; &#xFF1A; GET  /cart/</p>
<p>&#x8FD4;&#x56DE;&#x6570;&#x636E;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x662F;&#x5426;&#x5FC5;&#x987B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x5546;&#x54C1;sku id</td>
</tr>
<tr>
<td>count</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x6570;&#x91CF;</td>
</tr>
<tr>
<td>selected</td>
<td>bool</td>
<td>&#x662F;</td>
<td>&#x662F;&#x5426;&#x52FE;&#x9009;&#xFF0C;&#x9ED8;&#x8BA4;&#x52FE;&#x9009;</td>
</tr>
<tr>
<td>name</td>
<td>str</td>
<td>&#x662F;</td>
<td>&#x5546;&#x54C1;&#x540D;&#x79F0;</td>
</tr>
<tr>
<td>default_image_url</td>
<td>str</td>
<td>&#x662F;</td>
<td>&#x5546;&#x54C1;&#x9ED8;&#x8BA4;&#x56FE;&#x7247;</td>
</tr>
<tr>
<td>price</td>
<td>decimal</td>
<td>&#x662F;</td>
<td>&#x5546;&#x54C1;&#x5355;&#x4EF7;</td>
</tr>
</tbody>
</table>
<h4 id="&#x540E;&#x7AEF;&#x7F16;&#x5199;">&#x540E;&#x7AEF;&#x7F16;&#x5199;</h4>
<p>&#x5728;carts/serializers.py&#x4E2D;&#x521B;&#x5EFA;&#x5E8F;&#x5217;&#x5316;&#x5668;</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CartSKUSerializer</span><span class="hljs-params">(serializers.ModelSerializer)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x8D2D;&#x7269;&#x8F66;&#x5546;&#x54C1;&#x6570;&#x636E;&#x5E8F;&#x5217;&#x5316;&#x5668;
    &quot;&quot;&quot;</span>
    count = serializers.IntegerField(label=<span class="hljs-string">&apos;&#x6570;&#x91CF;&apos;</span>)
    selected = serializers.BooleanField(label=<span class="hljs-string">&apos;&#x662F;&#x5426;&#x52FE;&#x9009;&apos;</span>)

    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Meta</span>:</span>
        model = SKU
        fields = (<span class="hljs-string">&apos;id&apos;</span>, <span class="hljs-string">&apos;count&apos;</span>, <span class="hljs-string">&apos;name&apos;</span>, <span class="hljs-string">&apos;default_image_url&apos;</span>, <span class="hljs-string">&apos;price&apos;</span>, <span class="hljs-string">&apos;selected&apos;</span>)
</code></pre>
<p>&#x5728;carts/views.py &#x4E2D;&#x4FEE;&#x6539;&#x89C6;&#x56FE;&#xFF0C;&#x589E;&#x52A0;get&#x65B9;&#x6CD5;</p>
<pre><code class="lang-pytohn">class CartView(APIView):
    ...

    def get(self, request):
        &quot;&quot;&quot;
        &#x83B7;&#x53D6;&#x8D2D;&#x7269;&#x8F66;
        &quot;&quot;&quot;
        try:
            user = request.user
        except Exception:
            user = None

        if user is not None and user.is_authenticated:
            # &#x7528;&#x6237;&#x5DF2;&#x767B;&#x5F55;&#xFF0C;&#x4ECE;redis&#x4E2D;&#x8BFB;&#x53D6;
            redis_conn = get_redis_connection(&apos;cart&apos;)
            redis_cart = redis_conn.hgetall(&apos;cart_%s&apos; % user.id)
            redis_cart_selected = redis_conn.smembers(&apos;cart_selected_%s&apos; % user.id)
            cart = {}
            for key, val in redis_cart.items():
                cart[int(key)] = {
                    &apos;count&apos;: int(val),
                    &apos;selected&apos;: key in redis_cart_selected
                }
        else:
            # &#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;&#xFF0C;&#x4ECE;cookie&#x4E2D;&#x8BFB;&#x53D6;
            cart = request.COOKIES.get(&apos;cart&apos;)
            if cart is not None:
                cart = pickle.loads(base64.b64decode(cart.encode()))
            else:
                cart = {}

        # &#x904D;&#x5386;&#x5904;&#x7406;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;
        skus = SKU.objects.filter(id__in=cart.keys())
        for sku in skus:
            sku.count = cart[sku.id][&apos;count&apos;]
            sku.selected = cart[sku.id][&apos;selected&apos;]

        serializer = CartSKUSerializer(skus, many=True)
        return Response(serializer.data)
</code></pre>
<h4 id="&#x524D;&#x7AEF;&#x7F16;&#x5199;">&#x524D;&#x7AEF;&#x7F16;&#x5199;</h4>
<p>&#x4FEE;&#x6539;cart.html&#x6587;&#x4EF6;&#xFF0C;&#x589E;&#x52A0;Vue&#x53D8;&#x91CF;</p>
<pre><code class="lang-html"><span class="hljs-doctype">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">html</span> <span class="hljs-attribute">xmlns</span>=<span class="hljs-value">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span class="hljs-attribute">xml:lang</span>=<span class="hljs-value">&quot;en&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">meta</span> <span class="hljs-attribute">http-equiv</span>=<span class="hljs-value">&quot;Content-Type&quot;</span> <span class="hljs-attribute">content</span>=<span class="hljs-value">&quot;text/html;charset=UTF-8&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">title</span>&gt;</span>&#x7F8E;&#x591A;&#x5546;&#x57CE;-&#x8D2D;&#x7269;&#x8F66;<span class="hljs-tag">&lt;/<span class="hljs-title">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">link</span> <span class="hljs-attribute">rel</span>=<span class="hljs-value">&quot;stylesheet&quot;</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/css&quot;</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;css/reset.css&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">link</span> <span class="hljs-attribute">rel</span>=<span class="hljs-value">&quot;stylesheet&quot;</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/css&quot;</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;css/main.css&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/javascript&quot;</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">&quot;js/host.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/javascript&quot;</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">&quot;js/vue-2.5.16.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/javascript&quot;</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">&quot;js/axios-0.18.0.min.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">&quot;app&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;header_con&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;header&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;welcome fl&quot;</span>&gt;</span>&#x6B22;&#x8FCE;&#x6765;&#x5230;&#x7F8E;&#x591A;&#x5546;&#x57CE;!<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;fr&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">v-if</span>=<span class="hljs-value">&quot;username&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;login_btn fl&quot;</span>&gt;</span>
                    &#x6B22;&#x8FCE;&#x60A8;&#xFF1A;<span class="hljs-tag">&lt;<span class="hljs-title">em</span>&gt;</span>{{ username }}<span class="hljs-tag">&lt;/<span class="hljs-title">em</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">span</span>&gt;</span>|<span class="hljs-tag">&lt;/<span class="hljs-title">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">a</span> @<span class="hljs-attribute">click</span>=<span class="hljs-value">&quot;logout&quot;</span>&gt;</span>&#x9000;&#x51FA;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">v-else</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;login_btn fl&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;login.html&quot;</span>&gt;</span>&#x767B;&#x5F55;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">span</span>&gt;</span>|<span class="hljs-tag">&lt;/<span class="hljs-title">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;register.html&quot;</span>&gt;</span>&#x6CE8;&#x518C;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;user_link fl&quot;</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">span</span>&gt;</span>|<span class="hljs-tag">&lt;/<span class="hljs-title">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;user_center_info.html&quot;</span>&gt;</span>&#x7528;&#x6237;&#x4E2D;&#x5FC3;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">span</span>&gt;</span>|<span class="hljs-tag">&lt;/<span class="hljs-title">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;cart.html&quot;</span>&gt;</span>&#x6211;&#x7684;&#x8D2D;&#x7269;&#x8F66;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">span</span>&gt;</span>|<span class="hljs-tag">&lt;/<span class="hljs-title">span</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;user_center_order.html&quot;</span>&gt;</span>&#x6211;&#x7684;&#x8BA2;&#x5355;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>        
    <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;search_bar clearfix&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;index.html&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;logo fl&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">img</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">&quot;images/logo.png&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;sub_page_name fl&quot;</span>&gt;</span>|&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#x8D2D;&#x7269;&#x8F66;<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">form</span> <span class="hljs-attribute">method</span>=<span class="hljs-value">&quot;get&quot;</span> <span class="hljs-attribute">action</span>=<span class="hljs-value">&quot;/search.html&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;search_con fr mt40&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;input_text fl&quot;</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">&quot;q&quot;</span> <span class="hljs-attribute">placeholder</span>=<span class="hljs-value">&quot;&#x641C;&#x7D22;&#x5546;&#x54C1;&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;submit&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;input_btn fr&quot;</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">&quot;&quot;</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">&quot;&#x641C;&#x7D22;&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-title">form</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;total_count&quot;</span>&gt;</span>&#x5168;&#x90E8;&#x5546;&#x54C1;<span class="hljs-tag">&lt;<span class="hljs-title">em</span>&gt;</span>{{total_count}}<span class="hljs-tag">&lt;/<span class="hljs-title">em</span>&gt;</span>&#x4EF6;<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">ul</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;cart_list_th clearfix&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col01&quot;</span>&gt;</span>&#x5546;&#x54C1;&#x540D;&#x79F0;<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col03&quot;</span>&gt;</span>&#x5546;&#x54C1;&#x4EF7;&#x683C;<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col04&quot;</span>&gt;</span>&#x6570;&#x91CF;<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col05&quot;</span>&gt;</span>&#x5C0F;&#x8BA1;<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col06&quot;</span>&gt;</span>&#x64CD;&#x4F5C;<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">ul</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;cart_list_td clearfix&quot;</span> <span class="hljs-attribute">v-for</span>=<span class="hljs-value">&quot;(sku,index) in cart&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col01&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;checkbox&quot;</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">&quot;&quot;</span> <span class="hljs-attribute">v-model</span>=<span class="hljs-value">&quot;sku.selected&quot;</span> @<span class="hljs-attribute">change</span>=<span class="hljs-value">&quot;update_selected(index)&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col02&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">img</span> <span class="hljs-attribute">:src</span>=<span class="hljs-value">&quot;sku.default_image_url&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col03&quot;</span>&gt;</span>{{ sku.name }}<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col05&quot;</span>&gt;</span>{{ sku.price }}&#x5143;<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col06&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;num_add&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-title">a</span> @<span class="hljs-attribute">click</span>=<span class="hljs-value">&quot;on_add(index)&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;add fl&quot;</span>&gt;</span>+<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">v-model</span>=<span class="hljs-value">&quot;sku.count&quot;</span> @<span class="hljs-attribute">focus</span>=<span class="hljs-value">&quot;origin_input=sku.count&quot;</span> @<span class="hljs-attribute">blur</span>=<span class="hljs-value">&quot;on_input(index)&quot;</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;num_show fl&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-title">a</span> @<span class="hljs-attribute">click</span>=<span class="hljs-value">&quot;on_minus(index)&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;minus fl&quot;</span>&gt;</span>-<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col07&quot;</span>&gt;</span>{{sku.amount}}&#x5143;<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col08&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">a</span> @<span class="hljs-attribute">click</span>=<span class="hljs-value">&quot;on_delete(index)&quot;</span>&gt;</span>&#x5220;&#x9664;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">ul</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-title">ul</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;settlements&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col01&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;checkbox&quot;</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">&quot;&quot;</span> @<span class="hljs-attribute">change</span>=<span class="hljs-value">&quot;on_selected_all&quot;</span> <span class="hljs-attribute">v-model</span>=<span class="hljs-value">&quot;selected_all&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col02&quot;</span>&gt;</span>&#x5168;&#x9009;<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col03&quot;</span>&gt;</span>&#x5408;&#x8BA1;(&#x4E0D;&#x542B;&#x8FD0;&#x8D39;)&#xFF1A;<span class="hljs-tag">&lt;<span class="hljs-title">span</span>&gt;</span>&#xA5;<span class="hljs-tag">&lt;/<span class="hljs-title">span</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">em</span>&gt;</span>{{total_selected_amount}}<span class="hljs-tag">&lt;/<span class="hljs-title">em</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">br</span>&gt;</span>&#x5171;&#x8BA1;<span class="hljs-tag">&lt;<span class="hljs-title">b</span>&gt;</span>{{total_selected_count}}<span class="hljs-tag">&lt;/<span class="hljs-title">b</span>&gt;</span>&#x4EF6;&#x5546;&#x54C1;<span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">li</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;col04&quot;</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;place_order.html&quot;</span>&gt;</span>&#x53BB;&#x7ED3;&#x7B97;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-title">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">ul</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;footer&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;foot_link&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;#&quot;</span>&gt;</span>&#x5173;&#x4E8E;&#x6211;&#x4EEC;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">span</span>&gt;</span>|<span class="hljs-tag">&lt;/<span class="hljs-title">span</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;#&quot;</span>&gt;</span>&#x8054;&#x7CFB;&#x6211;&#x4EEC;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">span</span>&gt;</span>|<span class="hljs-tag">&lt;/<span class="hljs-title">span</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;#&quot;</span>&gt;</span>&#x62DB;&#x8058;&#x4EBA;&#x624D;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">span</span>&gt;</span>|<span class="hljs-tag">&lt;/<span class="hljs-title">span</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;#&quot;</span>&gt;</span>&#x53CB;&#x60C5;&#x94FE;&#x63A5;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>        
        <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">p</span>&gt;</span>CopyRight &#xA9; 2016 &#x5317;&#x4EAC;&#x7F8E;&#x591A;&#x5546;&#x4E1A;&#x80A1;&#x4EFD;&#x6709;&#x9650;&#x516C;&#x53F8; All Rights Reserved<span class="hljs-tag">&lt;/<span class="hljs-title">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">p</span>&gt;</span>&#x7535;&#x8BDD;&#xFF1A;010-****888    &#x4EAC;ICP&#x5907;*******8&#x53F7;<span class="hljs-tag">&lt;/<span class="hljs-title">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/javascript&quot;</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">&quot;/js/cart.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">html</span>&gt;</span>
</code></pre>
<p>&#x65B0;&#x5EFA;cart.js&#x6587;&#x4EF6;</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> vm = <span class="hljs-keyword">new</span> Vue({
    el: <span class="hljs-string">&apos;#app&apos;</span>,
    data: {
        host,
        username: sessionStorage.username || localStorage.username,
        user_id: sessionStorage.user_id || localStorage.user_id,
        token: sessionStorage.token || localStorage.token,
        cart: [],
        total_selected_count: <span class="hljs-number">0</span>,
        origin_input: <span class="hljs-number">0</span> <span class="hljs-comment">// &#x7528;&#x4E8E;&#x8BB0;&#x5F55;&#x624B;&#x52A8;&#x8F93;&#x5165;&#x524D;&#x7684;&#x503C;</span>
    },
    computed: {
        total_count: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-keyword">var</span> total = <span class="hljs-number">0</span>;
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-keyword">this</span>.cart.length; i++){
                total += <span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.cart[i].count);
                <span class="hljs-keyword">this</span>.cart[i].amount = (<span class="hljs-built_in">parseFloat</span>(<span class="hljs-keyword">this</span>.cart[i].price) * <span class="hljs-built_in">parseFloat</span>(<span class="hljs-keyword">this</span>.cart[i].count)).toFixed(<span class="hljs-number">2</span>);
            }
            <span class="hljs-keyword">return</span> total;
        },
        total_selected_amount: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-keyword">var</span> total = <span class="hljs-number">0</span>;
            <span class="hljs-keyword">this</span>.total_selected_count = <span class="hljs-number">0</span>;
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-keyword">this</span>.cart.length; i++){
                <span class="hljs-keyword">if</span>(<span class="hljs-keyword">this</span>.cart[i].selected) {
                    total += (<span class="hljs-built_in">parseFloat</span>(<span class="hljs-keyword">this</span>.cart[i].price) * <span class="hljs-built_in">parseFloat</span>(<span class="hljs-keyword">this</span>.cart[i].count));
                    <span class="hljs-keyword">this</span>.total_selected_count += <span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.cart[i].count);
                }
            }
            <span class="hljs-keyword">return</span> total.toFixed(<span class="hljs-number">2</span>);
        },
        selected_all: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-keyword">var</span> selected=<span class="hljs-literal">true</span>;
            <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-keyword">this</span>.cart.length; i++){
                <span class="hljs-keyword">if</span>(<span class="hljs-keyword">this</span>.cart[i].selected==<span class="hljs-literal">false</span>){
                    selected=<span class="hljs-literal">false</span>;
                    <span class="hljs-keyword">break</span>;
                }
            }
            <span class="hljs-keyword">return</span> selected;
        }
    },
    mounted: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-comment">// &#x83B7;&#x53D6;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</span>
        axios.get(<span class="hljs-keyword">this</span>.host+<span class="hljs-string">&apos;/cart/&apos;</span>, {
                headers: {
                    <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                },
                responseType: <span class="hljs-string">&apos;json&apos;</span>,
                withCredentials: <span class="hljs-literal">true</span>
            })
            .then(response =&gt; {
                <span class="hljs-keyword">this</span>.cart = response.data;
                <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-keyword">this</span>.cart.length; i++){
                    <span class="hljs-keyword">this</span>.cart[i].amount = (<span class="hljs-built_in">parseFloat</span>(<span class="hljs-keyword">this</span>.cart[i].price) * <span class="hljs-keyword">this</span>.cart[i].count).toFixed(<span class="hljs-number">2</span>);
                }
            })
            .catch(error =&gt; {
                <span class="hljs-built_in">console</span>.log(error.response.data);
            })
    },
    methods: {
        <span class="hljs-comment">// &#x9000;&#x51FA;</span>
        logout: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            sessionStorage.clear();
            localStorage.clear();
            location.href = <span class="hljs-string">&apos;/login.html&apos;</span>;
        },
        <span class="hljs-comment">// &#x51CF;&#x5C11;&#x64CD;&#x4F5C;</span>
        on_minus: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{
            <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.cart[index].count &gt; <span class="hljs-number">1</span>) {
                <span class="hljs-keyword">var</span> count = <span class="hljs-keyword">this</span>.cart[index].count - <span class="hljs-number">1</span>;
                <span class="hljs-keyword">this</span>.update_count(index, count);
            }
        },
        on_add: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{
            <span class="hljs-keyword">var</span> count = <span class="hljs-keyword">this</span>.cart[index].count + <span class="hljs-number">1</span>;
            <span class="hljs-keyword">this</span>.update_count(index, count);
        },
        on_selected_all: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-keyword">var</span> selected = !<span class="hljs-keyword">this</span>.selected_all;
            <span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-keyword">this</span>.cart.length;i++){
                <span class="hljs-keyword">this</span>.cart[i].selected = selected;
            }
        },
        <span class="hljs-comment">// &#x5220;&#x9664;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</span>
        on_delete: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{

        },
        on_input: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{
            <span class="hljs-keyword">var</span> val = <span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.cart[index].count);
            <span class="hljs-keyword">if</span> (<span class="hljs-built_in">isNaN</span>(val) || val &lt;= <span class="hljs-number">0</span>) {
                <span class="hljs-keyword">this</span>.cart[index].count = <span class="hljs-keyword">this</span>.origin_input;
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-comment">// &#x66F4;&#x65B0;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</span>
            }
        },
        <span class="hljs-comment">// &#x66F4;&#x65B0;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</span>
        update_count: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index, count</span>)</span>{

        },
        <span class="hljs-comment">// &#x66F4;&#x65B0;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</span>
        update_selected: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>) </span>{

        }
    }
});
</code></pre>
<h2 id="3--&#x4FEE;&#x6539;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;">3.  &#x4FEE;&#x6539;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</h2>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;</h4>
<p>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F; &#xFF1A; PUT  /cart/</p>
<p>&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x662F;&#x5426;&#x5FC5;&#x987B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>sku_id</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x5546;&#x54C1;sku id</td>
</tr>
<tr>
<td>count</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x6570;&#x91CF;</td>
</tr>
<tr>
<td>selected</td>
<td>bool</td>
<td>&#x5426;</td>
<td>&#x662F;&#x5426;&#x52FE;&#x9009;&#xFF0C;&#x9ED8;&#x8BA4;&#x52FE;&#x9009;</td>
</tr>
</tbody>
</table>
<p>&#x8FD4;&#x56DE;&#x6570;&#x636E;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x662F;&#x5426;&#x5FC5;&#x987B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>sku_id</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x5546;&#x54C1;sku id</td>
</tr>
<tr>
<td>count</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x6570;&#x91CF;</td>
</tr>
<tr>
<td>selected</td>
<td>bool</td>
<td>&#x662F;</td>
<td>&#x662F;&#x5426;&#x52FE;&#x9009;&#xFF0C;&#x9ED8;&#x8BA4;&#x52FE;&#x9009;</td>
</tr>
</tbody>
</table>
<h4 id="&#x540E;&#x7AEF;&#x89C6;&#x56FE;&#x7F16;&#x5199;">&#x540E;&#x7AEF;&#x89C6;&#x56FE;&#x7F16;&#x5199;</h4>
<p>&#x5728;carts/views.py&#x4E2D;&#x4FEE;&#x6539;&#x89C6;&#x56FE;&#xFF0C;&#x6DFB;&#x52A0;put&#x65B9;&#x6CD5;</p>
<pre><code class="lang-python">    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">put</span><span class="hljs-params">(self, request)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x4FEE;&#x6539;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;
        &quot;&quot;&quot;</span>
        serializer = CartSerializer(data=request.data)
        serializer.is_valid(raise_exception=<span class="hljs-keyword">True</span>)
        sku_id = serializer.data.get(<span class="hljs-string">&apos;sku_id&apos;</span>)
        count = serializer.data.get(<span class="hljs-string">&apos;count&apos;</span>)
        selected = serializer.data.get(<span class="hljs-string">&apos;selected&apos;</span>)

        <span class="hljs-comment"># &#x5C1D;&#x8BD5;&#x5BF9;&#x8BF7;&#x6C42;&#x7684;&#x7528;&#x6237;&#x8FDB;&#x884C;&#x9A8C;&#x8BC1;</span>
        <span class="hljs-keyword">try</span>:
            user = request.user
        <span class="hljs-keyword">except</span> Exception:
            <span class="hljs-comment"># &#x9A8C;&#x8BC1;&#x5931;&#x8D25;&#xFF0C;&#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;</span>
            user = <span class="hljs-keyword">None</span>

        <span class="hljs-keyword">if</span> user <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">None</span> <span class="hljs-keyword">and</span> user.is_authenticated:
            <span class="hljs-comment"># &#x7528;&#x6237;&#x5DF2;&#x767B;&#x5F55;&#xFF0C;&#x5728;redis&#x4E2D;&#x4FDD;&#x5B58;</span>
            redis_conn = get_redis_connection(<span class="hljs-string">&apos;cart&apos;</span>)
            pl = redis_conn.pipeline()
            pl.hset(<span class="hljs-string">&apos;cart_%s&apos;</span> % user.id, sku_id, count)
            <span class="hljs-keyword">if</span> selected:
                pl.sadd(<span class="hljs-string">&apos;cart_selected_%s&apos;</span> % user.id, sku_id)
            <span class="hljs-keyword">else</span>:
                pl.srem(<span class="hljs-string">&apos;cart_selected_%s&apos;</span> % user.id, sku_id)
            pl.execute()
            <span class="hljs-keyword">return</span> Response(serializer.data)
        <span class="hljs-keyword">else</span>:
            <span class="hljs-comment"># &#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;&#xFF0C;&#x5728;cookie&#x4E2D;&#x4FDD;&#x5B58;</span>
            <span class="hljs-comment"># &#x4F7F;&#x7528;pickle&#x5E8F;&#x5217;&#x5316;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;&#xFF0C;pickle&#x64CD;&#x4F5C;&#x7684;&#x662F;bytes&#x7C7B;&#x578B;</span>
            cart = request.COOKIES.get(<span class="hljs-string">&apos;cart&apos;</span>)
            <span class="hljs-keyword">if</span> cart <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">None</span>:
                cart = pickle.loads(base64.b64decode(cart.encode()))
            <span class="hljs-keyword">else</span>:
                cart = {}

            cart[sku_id] = {
                <span class="hljs-string">&apos;count&apos;</span>: count,
                <span class="hljs-string">&apos;selected&apos;</span>: selected
            }
            response = Response(serializer.data)
            response.set_cookie(<span class="hljs-string">&apos;cart&apos;</span>, base64.b64encode(pickle.dumps(cart)).decode())
            <span class="hljs-keyword">return</span> response
</code></pre>
<h4 id="&#x524D;&#x7AEF;&#x7F16;&#x5199;">&#x524D;&#x7AEF;&#x7F16;&#x5199;</h4>
<p>&#x5728;cart.js&#x4E2D;&#x6DFB;&#x52A0;</p>
<pre><code class="lang-js">        on_input: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{
            <span class="hljs-keyword">var</span> val = <span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.cart[index].count);
            <span class="hljs-keyword">if</span> (<span class="hljs-built_in">isNaN</span>(val) || val &lt;= <span class="hljs-number">0</span>) {
                <span class="hljs-keyword">this</span>.cart[index].count = <span class="hljs-keyword">this</span>.origin_input;
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-comment">// &#x66F4;&#x65B0;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</span>
                axios.put(<span class="hljs-keyword">this</span>.host+<span class="hljs-string">&apos;/cart/&apos;</span>, {
                        sku_id: <span class="hljs-keyword">this</span>.cart[index].id,
                        count: val,
                        selected: <span class="hljs-keyword">this</span>.cart[index].selected
                    }, {
                        headers:{
                            <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                        },
                        responseType: <span class="hljs-string">&apos;json&apos;</span>,
                        withCredentials: <span class="hljs-literal">true</span>
                    })
                    .then(response =&gt; {
                        <span class="hljs-keyword">this</span>.cart[index].count = response.data.count;
                    })
                    .catch(error =&gt; {
                        alert(error.response.data.message);
                        <span class="hljs-keyword">this</span>.cart[index].count = <span class="hljs-keyword">this</span>.origin_input;
                    })
            }
        },
        <span class="hljs-comment">// &#x66F4;&#x65B0;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</span>
        update_count: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index, count</span>)</span>{
            axios.put(<span class="hljs-keyword">this</span>.host+<span class="hljs-string">&apos;/cart/&apos;</span>, {
                    sku_id: <span class="hljs-keyword">this</span>.cart[index].id,
                    count,
                    selected: <span class="hljs-keyword">this</span>.cart[index].selected
                }, {
                    headers:{
                        <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                    },
                    responseType: <span class="hljs-string">&apos;json&apos;</span>,
                    withCredentials: <span class="hljs-literal">true</span>
                })
                .then(response =&gt; {
                    <span class="hljs-keyword">this</span>.cart[index].count = response.data.count;
                })
                .catch(error =&gt; {
                    alert(error.response.data.message);
                })
        },
        <span class="hljs-comment">// &#x66F4;&#x65B0;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</span>
        update_selected: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>) </span>{
            axios.put(<span class="hljs-keyword">this</span>.host+<span class="hljs-string">&apos;/cart/&apos;</span>, {
                    sku_id: <span class="hljs-keyword">this</span>.cart[index].id,
                    count: <span class="hljs-keyword">this</span>.cart[index].count,
                    selected: <span class="hljs-keyword">this</span>.cart[index].selected
                }, {
                    headers: {
                        <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                    },
                    responseType: <span class="hljs-string">&apos;json&apos;</span>,
                    withCredentials: <span class="hljs-literal">true</span>
                })
                .then(response =&gt; {
                    <span class="hljs-keyword">this</span>.cart[index].selected = response.data.selected;
                })
                .catch(error =&gt; {
                    alert(error.response.data.message);
                })
        }
</code></pre>
<h3 id="4--&#x5220;&#x9664;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;">4.  &#x5220;&#x9664;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</h3>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;</h4>
<p>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F; &#xFF1A; DELETE  /cart/</p>
<p>&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x662F;&#x5426;&#x5FC5;&#x987B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>sku_id</td>
<td>int</td>
<td>&#x662F;</td>
<td>&#x5546;&#x54C1;sku id</td>
</tr>
</tbody>
</table>
<h4 id="&#x540E;&#x7AEF;&#x7F16;&#x5199;">&#x540E;&#x7AEF;&#x7F16;&#x5199;</h4>
<p>&#x5728;carts/views.py &#x4E2D;&#x4FEE;&#x6539;&#x89C6;&#x56FE;&#xFF0C;&#x589E;&#x52A0;delete&#x65B9;&#x6CD5;</p>
<pre><code class="lang-python">    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">delete</span><span class="hljs-params">(self, request)</span>:</span>
        <span class="hljs-string">&quot;&quot;&quot;
        &#x5220;&#x9664;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;
        &quot;&quot;&quot;</span>
        serializer = CartDeleteSerializer(data=request.data)
        serializer.is_valid(raise_exception=<span class="hljs-keyword">True</span>)
        sku_id = serializer.data[<span class="hljs-string">&apos;sku_id&apos;</span>]

        <span class="hljs-keyword">try</span>:
            user = request.user
        <span class="hljs-keyword">except</span> Exception:
            <span class="hljs-comment"># &#x9A8C;&#x8BC1;&#x5931;&#x8D25;&#xFF0C;&#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;</span>
            user = <span class="hljs-keyword">None</span>

        <span class="hljs-keyword">if</span> user <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">None</span> <span class="hljs-keyword">and</span> user.is_authenticated:
            <span class="hljs-comment"># &#x7528;&#x6237;&#x5DF2;&#x767B;&#x5F55;&#xFF0C;&#x5728;redis&#x4E2D;&#x4FDD;&#x5B58;</span>
            redis_conn = get_redis_connection(<span class="hljs-string">&apos;cart&apos;</span>)
            pl = redis_conn.pipeline()
            pl.hdel(<span class="hljs-string">&apos;cart_%s&apos;</span> % user.id, sku_id)
            pl.srem(<span class="hljs-string">&apos;cart_selected_%s&apos;</span> % user.id, sku_id)
            pl.execute()
            <span class="hljs-keyword">return</span> Response(status=status.HTTP_204_NO_CONTENT)
        <span class="hljs-keyword">else</span>:
            <span class="hljs-comment"># &#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;&#xFF0C;&#x5728;cookie&#x4E2D;&#x4FDD;&#x5B58;</span>
            response = Response(status=status.HTTP_204_NO_CONTENT)

            <span class="hljs-comment"># &#x4F7F;&#x7528;pickle&#x5E8F;&#x5217;&#x5316;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;&#xFF0C;pickle&#x64CD;&#x4F5C;&#x7684;&#x662F;bytes&#x7C7B;&#x578B;</span>
            cart = request.COOKIES.get(<span class="hljs-string">&apos;cart&apos;</span>)
            <span class="hljs-keyword">if</span> cart <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">None</span>:
                cart = pickle.loads(base64.b64decode(cart.encode()))
                <span class="hljs-keyword">if</span> sku_id <span class="hljs-keyword">in</span> cart:
                    <span class="hljs-keyword">del</span> cart[sku_id]
                    response.set_cookie(<span class="hljs-string">&apos;cart&apos;</span>, base64.b64encode(pickle.dumps(cart)).decode())
            <span class="hljs-keyword">return</span> response
</code></pre>
<h4 id="&#x524D;&#x7AEF;&#x7F16;&#x5199;">&#x524D;&#x7AEF;&#x7F16;&#x5199;</h4>
<p>&#x5728;cart.js&#x4E2D;&#x589E;&#x52A0;</p>
<pre><code class="lang-js">        <span class="hljs-comment">// &#x5220;&#x9664;&#x8D2D;&#x7269;&#x8F66;&#x6570;&#x636E;</span>
        on_delete: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index</span>)</span>{
            axios.delete(<span class="hljs-keyword">this</span>.host+<span class="hljs-string">&apos;/cart/&apos;</span>, {
                    data: {
                        sku_id: <span class="hljs-keyword">this</span>.cart[index].id
                    },
                    headers:{
                        <span class="hljs-string">&apos;Authorization&apos;</span>: <span class="hljs-string">&apos;JWT &apos;</span> + <span class="hljs-keyword">this</span>.token
                    },
                    responseType: <span class="hljs-string">&apos;json&apos;</span>,
                    withCredentials: <span class="hljs-literal">true</span>
                })
                .then(response =&gt; {
                    <span class="hljs-keyword">this</span>.cart.splice(index, <span class="hljs-number">1</span>);
                })
                .catch(error =&gt; {
                    <span class="hljs-built_in">console</span>.log(error.response.data);
                })
        },
</code></pre>
<h4 id=""> </h4>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../C04-Cart/DataStructureDesign.html" class="navigation navigation-prev " aria-label="Previous page: 购物车数据存储设计"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../C04-Cart/MergeCart.html" class="navigation navigation-next " aria-label="Next page: 登录合并购物车"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
